Skip to content

test(streaming): add empty-monitors edge case for stream_alerts#42

Draft
KhaledSalhab-Develeap wants to merge 4 commits into
feat/6bdf93-async-streaming-helpersfrom
test/0db470-stream-alerts-empty
Draft

test(streaming): add empty-monitors edge case for stream_alerts#42
KhaledSalhab-Develeap wants to merge 4 commits into
feat/6bdf93-async-streaming-helpersfrom
test/0db470-stream-alerts-empty

Conversation

@KhaledSalhab-Develeap

Copy link
Copy Markdown
Collaborator

Add three unit tests to TestStreamAlerts in tests/unit/test_streaming.py covering the edge case where stream_alerts() is called and the monitors list returned by the API is empty.

What changed

  • tests/unit/test_streaming.py: three new tests added to TestStreamAlerts:
    • test_stream_alerts_empty_monitors_yields_nothing -- empty list on the first poll yields no alerts
    • test_stream_alerts_empty_monitors_sleep_still_called -- asyncio.sleep is still invoked when monitors is empty (the loop does not exit early)
    • test_stream_alerts_empty_then_monitors_appear_no_transition -- monitors present on the second poll after an empty first poll set the baseline without emitting a transition alert, because there is no prior state to diff against

Why this shape

The three tests each pin a distinct observable behaviour of the empty path: no yield, no early exit, and correct baseline initialisation. Splitting them makes each failure message self-describing. No production code changes are required; the existing implementation already handles this path correctly.

Verification

Check Result
pytest tests/unit/test_streaming.py --no-cov 20 passed (17 pre-existing + 3 new)
No production code modified confirmed

Acceptance criteria

  • stream_alerts() with an empty monitors list correctly yields nothing
  • baseline is empty after the first empty poll (observable via the no-transition test on second poll)
  • the path has unit test coverage guarding against regressions

…470)

Guard the path where stream_alerts receives an empty monitors list on
first poll: verify nothing is yielded, asyncio.sleep is still called
(the loop continues), and monitors appearing on the second poll set
the baseline without triggering transition alerts.
Same pyproject/test/uv.lock resolution as the parent async-streaming branch.
Note: this branch shares the test/0db470 head with PR #42 (based on the
async-streaming branch) and carries the same standalone-failing test_otel.py;
the OTel client wiring lands in PR #40.
Same as the parent async-streaming branch: _otel.py and test_otel.py require
the PY-11 client wiring that is not present here, so they were dead code plus a
failing standalone test. Remove them and the opentelemetry deps. OTel is
delivered solely by the PY-11 PR.
Reconcile the divergent main-merge so this PR's diff against its parent shows
only the empty-monitors stream_alerts test (the actual change), not the whole
rebased delta.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant